package command

import (
	"fmt"
	"project/design/command/commands"
)

type RemoteControl struct {
	onCommands  []commands.Command
	offCommands []commands.Command
	//上一个命令，用于撤回操作，理论上要用栈实现，这里简单化就算了
	previousCommand commands.Command
}

func CreateRemoteControl(lines int) *RemoteControl {
	res := new(RemoteControl)
	res.onCommands = make([]commands.Command, lines)
	res.offCommands = make([]commands.Command, lines)
	res.previousCommand = commands.CreateNothing()
	return res
}

func (rc *RemoteControl) SetCommand(pos int, onCommand commands.Command, offCommand commands.Command) {
	rc.onCommands[pos] = onCommand
	rc.offCommands[pos] = offCommand
}

//某个位置的开
func (rc *RemoteControl) OnButtonPushed(pos int) {
	rc.onCommands[pos].Execute()
	rc.previousCommand = rc.onCommands[pos]
}

//某个位置的关
func (rc *RemoteControl) OffButtonPushed(pos int) {
	rc.offCommands[pos].Execute()
	rc.previousCommand = rc.offCommands[pos]
}

//全局的撤销
func (rc *RemoteControl) UndoButtonPushed() {
	fmt.Print("撤销后：")
	rc.previousCommand.Undo()
}

//打开所有

//关闭所有
